/*
 * User: user
 * Date: 20/12/2007
 * Time: 00:50:28
 */
package org.conann.metadata.validation;

import static com.google.common.base.Preconditions.checkNotNull;
import org.conann.metadata.records.TypeRecord;

import javax.webbeans.scope.Dependent;
import static java.lang.reflect.Modifier.isFinal;

public class TypeValidator extends RecordValidator<TypeRecord<?>> {

    @Override
    public void validate (TypeRecord<?> record) {
        checkNotNull(record);
        validateDependentScope(record);
    }

    private void validateDependentScope (TypeRecord<?> record) {
        final Class<?> type = record.getType();
        if (isFinal(type.getModifiers())) {
            check(record.isAnnotatedBy(Dependent.class), "{0} is a final class and should be annotated with @{1}", type, Dependent.class.getSimpleName());
        }
    }
}